package com.mehdiuz.backend.commons.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalTime;
import java.util.Date;

@Component
public class DateFillHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        boolean createTime = metaObject.hasSetter("createTime");
        if(createTime){
            setFieldValByName("createTime", new Date(),metaObject);
        }

        boolean is_deleted = metaObject.hasSetter("is_deleted");
        if(is_deleted){
            setFieldValByName("is_deleted", 0,metaObject);
        }
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        boolean createTime = metaObject.hasSetter("updateTime");
        if(createTime){
            setFieldValByName("updateTime", new Date(),metaObject);
        }
    }
}
